using System;
using System.Collections.Generic;
using Clandestine.Engines.Field;
using Qyoto;

namespace Shlick.LayerModel
{
	internal class MapItem : Item
	{
		public Map Map { get; private set; }
		
		private MapItem(Map item, MapDocument mapDocument, LayerTreeMode mode) : base(item, mapDocument, mode)
		{
			this.Map = item;
		}
		
		public static MapItem Get(Map item, MapDocument mapDocument, LayerTreeMode mode)
		{
			if (cachedItems.ContainsKey(mode) && cachedItems[mode].ContainsKey(item))
				return (MapItem)cachedItems[mode][item];
			else
				return new MapItem(item, mapDocument, mode);
		}
	
		public override int Row()
		{
			return 0; // Map is always 0! :)
		}
	
		public override Item Child(int row)
		{
			return LevelItem.Get(this.Map.Levels[this.Map.Levels.Count - row - 1], this.MapDocument, this.Mode);
		}
		
		public override Item Parent()
		{
			return null;
		}
		
		public override int ChildrenCount()
		{
			return this.Map.Levels.Count;
		}
		
		public override string GetData()
		{
			 return String.Format("Map");
		}
		
		public override string GetName()
		{
			return this.Map.Name;
		}
		
		public override bool SetName(string name)
		{
			this.Map.Name = name;
			return true;
		}
		
		public override bool? IsVisible()
		{
			 return null;
		}
	}
}